package one.two.eleven;

import java.text.SimpleDateFormat;

public class Date {
	private final int month;
	private final int day;
	private final int year;

	public Date(int m, int d, int y) throws Exception {
		if (!valid(m, d, y)) {
			throw new Exception("Unvalid date");
		}
		month = m;
		day = d;
		year = y;
	}

	static boolean valid(int m, int d, int y) {
		try {
			SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
			sdf.setLenient(false);
			sdf.parse(y + "/" + m + "/" + d);
		} catch (Exception e) {
			return false;
		}
		return true;
	}

	public int month() {
		return month;
	}

	public int day() {
		return day;
	}

	public int year() {
		return day;
	}

	public String dayOfWeek() throws Exception {
		String[] a = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday" };
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy/MM/dd");
		java.util.Date d = sdf.parse(year + "/" + month + "/" + day);
		return a[d.getDay()];
	}

	public String toString() {
		return month() + "/" + day() + "/" + year();
	}

	public static void main(String[] args) throws Exception {
		Date d = new Date(1, 21, 2010);
		System.out.println(d.dayOfWeek());
	}

}
